class code6 {
    //二分
    ArrayList<Integer> list;
    int left = 0;//下次直接从上次的left开始二分

    public RecentCounter() {
        list = new ArrayList<>();
    }

    public int ping(int t) {
        list.add(t);
        int right = list.size();
        while(left < right) {
            int mid = left + (right-left)/2;
            if(list.get(mid) < t-3000) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return list.size()-left;
    }
}

/**
 * Your RecentCounter object will be instantiated and called as such:
 * RecentCounter obj = new RecentCounter();
 * int param_1 = obj.ping(t);
 */